package com.car.web.controller.index;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.car.dal.dao.client.TgClientDao;
import com.car.dal.dao.client.TgClientImpDao;
import com.car.dal.dao.department.TgDepartmentDao;
import com.car.dal.dao.moneys.TgMoneyDao;
import com.car.dal.dao.office.TgOfficeDao;
import com.car.dal.dao.reception.TgReceptionDao;
import com.car.dal.dao.reserve.TgReserveDao;
import com.car.dal.dao.source.TgSourceDao;
import com.car.dal.dao.sudent.StudentDao;
import com.car.dal.dao.task.TgTaskDao;
import com.car.dal.dao.user.UserDao;
import com.car.dal.dao.user.UserinfoDao;
import com.car.dal.dao.user.UsernamesDao;
import com.car.dal.dao.usergroup.TgUsergroupDao;
import com.car.dal.dao.work.TgworkDao;
import com.car.dal.object.TeaWeek;
import com.car.dal.object.TgMoney;
import com.car.dal.object.TgOffice;
import com.car.dal.object.TgReception;
import com.car.dal.object.TgReserve;
import com.car.dal.object.TgUserinfo;
import com.car.dal.object.TgUsernames;
import com.car.dal.object.YuWt;
import com.car.service.money.MoneyService;
import com.car.service.reception.ReceptionService;
import com.car.util.DateUtil;
import com.car.util.JsonExecutor;
import com.car.util.Page;
import com.car.util.Result;
import com.car.util.ResultSupport;
import com.car.util.WebExecutor;
import com.car.util.JsonExecutor.JsonBiz;
import com.car.util.WebExecutor.Biz;
import com.car.util.WriterExcel;
import com.car.web.controller.base.BaseController;
import com.car.web.controller.base.BaseVo;

/**
 * 网推部门跟踪
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping("/achieve")
public class AchieveController extends BaseController {

	private static final Logger logger = Logger
			.getLogger(AchieveController.class);
    @Resource
    private UserDao userDao;
    @Resource
	private TgworkDao workDao;
    @Resource
    private TgUsergroupDao tgUsergroupDao;
    @Resource
    private TgDepartmentDao tgDepartmentDao;
    @Resource
    private UserinfoDao userinfoDao;
    @Resource
    private TgOfficeDao tgOfficeDao;
	@Resource
	private TgTaskDao stateDao;
	@Resource
	private TgClientDao clientDao;
	@Resource
	private StudentDao studentDao;
	@Resource
	private TgClientImpDao clientImpDao;
	@Resource
	private TgSourceDao sourceDao;
    @Resource
    private TgReceptionDao receptionDao;
    @Resource
 	private TgReserveDao reserveDao;
    @Resource
 	private TgMoneyDao moneyDao;
    @Resource
    private ReceptionService receptionService;
    @Resource
    private MoneyService moneyService;
    @Resource
    private UsernamesDao usernamesDao;
    
    
 	//咨询师预约到访统计
    @RequestMapping(value = "/yuyue_daofang")
	public ModelAndView yuyueAnddaofang(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, final HttpServletResponse response)
			throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String time = request.getParameter("time");
					String nickname = request.getParameter("nickname");
					String regions = request.getParameter("regions");
					
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
					
					TgUserinfo user  = new TgUserinfo();
					String startTime = "";
					String endTime = "";
					if((time!=null && !time.equals(""))){
	   					startTime = sdf.format(DateUtil.getMonthFirst(time));
	   					endTime = sdf.format(DateUtil.getMonthLast(time));
	   				}else{
	   					time = sd.format(new Date());
	   					startTime = sdf.format(DateUtil.getMonthFirst(sdf.format(new Date())));
	   					endTime = sdf.format(DateUtil.getMonthLast(sdf.format(new Date())));
	   				}
					user.setJob("在线课程顾问");
					user.setRegions(regions);
	   				user.setNickname(nickname);
	   				List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user);
	   				user.setJob("课程顾问");
	   				List<TgUserinfo> uList =userinfoDao.getUserInfoByUserInfo(user);
	   				uList.addAll(uList1);
	   				if(uList!=null && uList.size()>0){
	   					TgReserve reserve = new TgReserve();
	   					for(TgUserinfo u:uList){
	   						reserve.setUsername(u.getUsername());
	   						reserve.setNon(0);
	   						reserve.setState(2);
	   						reserve.setSdate(sdf.parse(startTime));
	   						reserve.setEdate(sdf.parse(endTime));
	   						List<TgReserve> rlist = reserveDao.getReserve(reserve);
	   						if(rlist!=null && rlist.size()>0){
	   							HashMap<String, Integer> hs = new HashMap<String, Integer>();
	   							Integer zon = 0;
	   							for (TgReserve r : rlist) {
	   								Integer count = 1;
	   								if(r.getReceuser()!=null && !r.getReceuser().equals("")){
	   									if(!r.getReceuser().equals(u.getNickname())){
		   									if(r.getProvince()!=null && !"".equals(r.getProvince())){
		   										if (hs.get(r.getReceuser()) != null) {
				   									count = hs.get(r.getReceuser()) + 1;
				   								}
				   								hs.put(r.getReceuser(), count);
				   								zon++;
		   									}
		   								}
	   								}else{
	   									if(!r.getReceptioner().equals(u.getNickname())){
		   									if(r.getProvince()!=null && !"".equals(r.getProvince())){
		   										if (hs.get(r.getReceptioner()) != null) {
				   									count = hs.get(r.getReceptioner()) + 1;
				   								}
				   								hs.put(r.getReceptioner(), count);
				   								zon++;
		   									}
		   								}
	   								}
	   							}
	   							u.setTotrate(hs+"");
	   							u.setZonCount(zon);
	   						}
	   						
	   					}
	   				}
					result.setDefaultModel("time", time);
					result.setDefaultModel("uList", uList);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("system/achieve/system_yuyue_daofang", modelMap);
	}
    
    //竞价预约到访统计
    @RequestMapping(value = "/yuyue_daofang_wt")
	public ModelAndView yuyue_daofang_wt(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, final HttpServletResponse response)
			throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String time = request.getParameter("time");
					
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
					
					String startTime = "";
					String endTime = "";
					if((time!=null && !time.equals(""))){
	   					startTime = sdf.format(DateUtil.getMonthFirst(time));
	   					endTime = sdf.format(DateUtil.getMonthLast(time));
	   				}else{
	   					time = sd.format(new Date());
	   					startTime = sdf.format(DateUtil.getMonthFirst(sdf.format(new Date())));
	   					endTime = sdf.format(DateUtil.getMonthLast(sdf.format(new Date())));
	   				}
					
					List<YuWt> list = new ArrayList<YuWt>();
					YuWt yw1 = new YuWt();
					yw1.setNickname("李孝平");
					yw1.setUsername("lixiaoping");
					yw1.setKeyname("1.CCFC80D6BFE1,l0j9fitg3t94,lyx063wpay9l,kzpctoxsbclx,251mokab1mtn,lixianbao,shangqiaogt,edhhjon7t6za,13b6lzltt0xk,0n2njx5zmzvo。2.4D189169D77E。3.frvmppoifgmb。4.eyxl17rri7xu");
					yw1.setPingtai1("百度，百度搜索，百度推广，百度推课，百度网盟，离线宝，商桥沟通，商桥留言，网站报名，网站留言（CCFC80D6BFE1,l0j9fitg3t94,lyx063wpay9l,kzpctoxsbclx,251mokab1mtn,lixianbao,shangqiaogt,edhhjon7t6za,13b6lzltt0xk,0n2njx5zmzvo）");
					yw1.setPingtai2("百度信息流（4D189169D77E）");
					yw1.setPingtai3("今日头条广告（frvmppoifgmb）");
					yw1.setPingtai4("搜狗搜索（eyxl17rri7xu）");
					yw1.setQuyu1("北京，深圳，苏州，南京，重庆。");
					yw1.setQuyu2("全部区域");
					yw1.setQuyu3("北京，深圳，重庆，武汉，上海，天津，成都，杭州，宁波，长沙，沈阳");
					yw1.setQuyu4("全部区域");
					YuWt yw2 = new YuWt();
					yw2.setNickname("沈立成");
					yw2.setUsername("shenlicheng");
					yw2.setKeyname("1.CCFC80D6BFE1,l0j9fitg3t94,lyx063wpay9l,kzpctoxsbclx,251mokab1mtn,lixianbao,shangqiaogt,edhhjon7t6za,13b6lzltt0xk,0n2njx5zmzvo。2.B25FBBF42595。3.zgviq7wj9j0p");
					yw2.setPingtai1("百度，百度搜索，百度推广，百度推课，百度网盟，离线宝，商桥沟通，商桥留言，网站报名，网站留言（CCFC80D6BFE1,l0j9fitg3t94,lyx063wpay9l,kzpctoxsbclx,251mokab1mtn,lixianbao,shangqiaogt,edhhjon7t6za,13b6lzltt0xk,0n2njx5zmzvo）");
					yw2.setPingtai2("今日头条（B25FBBF42595）");
					yw2.setPingtai3("360搜索（zgviq7wj9j0p）");
					yw2.setQuyu1("上海，广州，天津，成都，杭州，宁波，沈阳");
					yw2.setQuyu2("南京，无锡，苏州，广州");
					yw2.setQuyu3("全部区域");
					YuWt yw3 = new YuWt();
					yw3.setNickname("陈正宗");
					yw3.setUsername("chenzhengzong");
					yw3.setKeyname("1.F819056877F8。2.02FAC12A4746。3.CCFC80D6BFE1。4.osjrem0am5af");
					yw3.setPingtai1("商务通神马（F819056877F8）");
					yw3.setPingtai2("百度糯米团购（2.02FAC12A4746）");
					yw3.setPingtai3("百度（CCFC80D6BFE1）");
					yw3.setPingtai4("微博粉丝通问卷（osjrem0am5af）");
					yw3.setQuyu1("全部区域");
					yw3.setQuyu2("全部区域");
					yw3.setQuyu3("无锡，武汉，长沙");
					yw3.setQuyu4("全部区域");
					/*SELECT c.source sourcens,c.invalid,c.province,c.city
					FROM tg_reserve r
					LEFT JOIN tg_client c ON r.client=c.`keyname`
					LEFT JOIN tg_source s ON c.source=s.`keyname` WHERE 1=1 AND r.non=0 AND r.state=2 and r.date >= "2017-3-1" AND r.date <= "2017-3-31" AND "CCFC80D6BFE1,l0j9fitg3t94,lyx063wpay9l,kzpctoxsbclx,251mokab1mtn,lixianbao,shangqiaogt,edhhjon7t6za,13b6lzltt0xk,0n2njx5zmzvo,4D189169D77E,B25FBBF42595,eyxl17rri7xu1,zgviq7wj9j0p,F819056877F8,02FAC12A4746,osjrem0am5af" like concat('%',s.keyname, '%')
					*/
					TgReserve reserve = new TgReserve();
					reserve.setSourcens(yw1.getKeyname()+yw2.getKeyname()+yw3.getKeyname());
					reserve.setNon(0);
					reserve.setState(2);
					reserve.setSdate(sdf.parse(startTime));
					reserve.setEdate(sdf.parse(endTime));
					List<TgReserve> rlist = reserveDao.getReserve2(reserve);
					if(rlist!=null && rlist.size()>0){
						Integer zon1 = 0;
						Integer zon2 = 0;
						Integer zon3 = 0;
						for(TgReserve r:rlist){
							//李孝平
							if(yw1.getKeyname().contains(r.getSourcens())){
								if(yw1.getPingtai1().contains(r.getSourcens())){
									if(r.getCity()!=null){
										if(yw1.getQuyu1().contains(r.getCity()) || yw1.getQuyu1().contains(r.getProvince())){
											zon1++;
										}
									}
								}
								if(yw1.getPingtai2().contains(r.getSourcens())){
									zon1++;
								}
								if(yw1.getPingtai3().contains(r.getSourcens())){
									if(r.getCity()!=null){
										if(yw1.getQuyu3().contains(r.getCity()) || yw1.getQuyu3().contains(r.getProvince())){
											zon1++;
										}
									}
								}
								if(yw1.getPingtai4().contains(r.getSourcens())){
									zon1++;
								}
								
							}
							
							//沈立成
							if(yw2.getKeyname().contains(r.getSourcens())){
								if(yw2.getPingtai1().contains(r.getSourcens())){
									if(r.getCity()!=null){
										if(yw2.getQuyu1().contains(r.getCity()) || yw2.getQuyu1().contains(r.getProvince())){
											zon2++;
										}
									}
								}
								
								if(yw2.getPingtai2().contains(r.getSourcens())){
									if(r.getCity()!=null){
										if(yw2.getQuyu2().contains(r.getCity()) || yw2.getQuyu2().contains(r.getProvince())){
											zon2++;
										}
									}
								}
								
								if(yw2.getPingtai3().contains(r.getSourcens())){
									zon2++;
								}
							}
							
							//陈正宗
							if(yw3.getKeyname().contains(r.getSourcens())){
								if(yw3.getPingtai1().contains(r.getSourcens())){
									zon3++;
								}
								if(yw3.getPingtai2().contains(r.getSourcens())){
									zon3++;
								}
								if(yw3.getPingtai3().contains(r.getSourcens())){
									if(r.getCity()!=null){
										if(yw3.getQuyu3().contains(r.getCity()) || yw3.getQuyu3().contains(r.getProvince())){
											zon2++;
										}
									}
								}
								if(yw3.getPingtai4().contains(r.getSourcens())){
									zon3++;
								}
							}
						}
						yw1.setZon(zon1);
						yw2.setZon(zon2);
						yw3.setZon(zon3);
					}
				
					list.add(yw1);
					list.add(yw2);
					list.add(yw3);
					result.setDefaultModel("time", time);
					result.setDefaultModel("list", list);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("system/achieve/system_yuyue_daofangWt", modelMap);
	}
    
    //咨询师业绩周统计
  	@RequestMapping(value = "/system_static_week")
  	public ModelAndView system_static_week(ModelMap modelMap, final BaseVo vo,
  			final HttpServletRequest request, final HttpServletResponse response)
  			throws Exception {
  		modelMap = WebExecutor.execute(logger, vo, new Biz() {
  			public Result process() {
  				Result result = new ResultSupport(true);
  				try {
  					String startTime = request.getParameter("startTime");
  					String endTime = request.getParameter("endTime");
  					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  					
  					if(startTime==null || "".equals(startTime) ||
  							endTime==null || "".equals(endTime)){
  						return result;
  					}else{
  						result.setDefaultModel("startTime", startTime);
  						result.setDefaultModel("endTime", endTime);
  					}
  					
  					List<TeaWeek> list = new ArrayList<TeaWeek>();
  					TgMoney money = new TgMoney();
  					TgMoney money1 = new TgMoney();
  					TgMoney money2 = new TgMoney();
  					TgMoney money3 = new TgMoney();
  					TgMoney money4 = new TgMoney();
  					TgReception reception = new TgReception();
  					TgUserinfo info = new TgUserinfo();
  					TgUsernames us = new TgUsernames();
  					info.setJob("课程顾问");
  					List<TgUserinfo> teaList = userinfoDao.getUserlistByType(info);
  					if(teaList!=null && teaList.size()>0){
  						Long stime = sdf.parse(startTime).getTime()/1000;
  						Long etime = sdf.parse(endTime).getTime()/1000;
  						for(TgUserinfo u:teaList){
  							double moneys=0.0;
  							Integer cdCount=0;
  							TeaWeek week = new TeaWeek();
  							week.setNickname(u.getNickname());
  							week.setCenter(u.getRegions());
  							
  							us.setUsernames(u.getUsername());
  							TgUsernames us2 = usernamesDao.getUsernamesByType2(us);
  							if(us2!=null){
  								week.setDj_nickname(us2.getNickname());
  							}
  							
  							money.setUsername(u.getUsername());
  							money.setStartTime(startTime);
  							money.setEndTime(endTime);
  							money.setMoneyType1(1);
  							List<TgMoney> mlist = moneyDao.getMoneysStaticByType(money);
  							if(mlist!=null && mlist.size()>0){
  								for(TgMoney m:mlist){
  									moneys +=m.getMoneys();
  								}
  							}
  							week.setXzMoneys(moneys);//当周新增业绩
  							
  							//接待测评量
  							reception.setUsername(u.getUsername());
  							reception.setStartTime(stime);
  							reception.setEndTime(etime);
  							week.setCpCount(receptionService.getZonlReceptionCount(reception));
  							
  							//成单数
  							money1.setUsername(u.getUsername());
  							money1.setEndTime(endTime);
  							Integer count =moneyService.getZonCdByMoneys(money, money1, sdf.parse(startTime), sdf.parse(endTime));
  							week.setJtCount(count);
  							
  							//市场新增业绩
  							money2.setPra_type(4);
  							money2.setState(1);
  							money2.setMoneyType1(1);
  							List<TgMoney> tyList = moneyDao.getMoneysByType3(money2);//太优的算市场的，不管什么渠道
  							Double moneys2 = 0.0;
  							if(tyList!=null && tyList.size()>0){
  								for(TgMoney m:tyList){
  									moneys2 +=m.getMoneys();
  									
  									//当周市场成单数
  									if(m.getMoneyType2()==1){
  										cdCount++;
  									}else if(m.getMoneyType2()==2){
  										money4.setStu_id(m.getStu_id());
  										List<TgMoney> clist2 = moneyDao.getMoneysStaticByType(money4);
  										if(clist2!=null && clist2.size()>0){
  											cdCount++;
  										}
  									}
  								}
  							}
  							
  							money3.setUsername(u.getUsername());
  							money3.setStartTime(startTime);
  							money3.setEndTime(sdf.format(DateUtil.getTommorrowDay1(sdf.parse(endTime))));
  							mlist = moneyDao.getMoneysScStaticByType(money3);
  							if(mlist!=null && mlist.size()>0){
  								for(TgMoney m:mlist){
  									moneys2 +=m.getMoneys();
  									
  									//当周市场成单数
  									if(m.getMoneyType2()==1){
  										cdCount++;
  									}else if(m.getMoneyType2()==2){
  										money4.setStu_id(m.getStu_id());
  										List<TgMoney> clist2 = moneyDao.getMoneysStaticByType(money4);
  										if(clist2!=null && clist2.size()>0){
  											cdCount++;
  										}
  									}
  								}
  							}
  							week.setScMoney(moneys2);
  							week.setSccdCount(cdCount);
  							
  							//市场接待测评量
  							reception.setSource("3p5idbdw49di,ct5yq4jhc6c7,gx50j0s9hrr1,wtukdq8gp65h,B76B4D3BFB7A,5077779E7889");
  							week.setScCount(receptionDao.getReceCountByType(reception));
  							list.add(week);
  						}
  					}
  					result.setDefaultModel("list", list);
  				} catch (Exception e) {
  					// TODO Auto-generated catch block
  					e.printStackTrace();
  				}
  				return result;
  			}
  		});

  		return new ModelAndView("system/achieve/system_jixiao_week", modelMap);
  	}
  	
  	
  	//咨询师业绩周统计下载
  	@RequestMapping(value = "/system_static_weekXz")
  	public ModelAndView system_static_weekXz(ModelMap modelMap, final BaseVo vo,
  			final HttpServletRequest request, final HttpServletResponse response)
  			throws Exception {
  		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
  			public Result process() {
  				Result result = new ResultSupport(true);
  				try {
  					String startTime = request.getParameter("startTime");
  					String endTime = request.getParameter("endTime");
  					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  					
  					if(startTime==null || "".equals(startTime) ||
  							endTime==null || "".equals(endTime)){
  						return result;
  					}else{
  						result.setDefaultModel("startTime", startTime);
  						result.setDefaultModel("endTime", endTime);
  					}
  					
  					List<TeaWeek> list = new ArrayList<TeaWeek>();
  					TgMoney money = new TgMoney();
  					TgMoney money1 = new TgMoney();
  					TgMoney money2 = new TgMoney();
  					TgMoney money3 = new TgMoney();
  					TgMoney money4 = new TgMoney();
  					TgReception reception = new TgReception();
  					TgUserinfo info = new TgUserinfo();
  					TgUsernames us = new TgUsernames();
  					info.setJob("课程顾问");
  					List<TgUserinfo> teaList = userinfoDao.getUserlistByType(info);
  					if(teaList!=null && teaList.size()>0){
  						Long stime = sdf.parse(startTime).getTime()/1000;
  						Long etime = sdf.parse(endTime).getTime()/1000;
  						for(TgUserinfo u:teaList){
  							double moneys=0.0;
  							Integer cdCount=0;
  							TeaWeek week = new TeaWeek();
  							week.setNickname(u.getNickname());
  							week.setCenter(u.getRegions());
  							
  							us.setUsernames(u.getUsername());
  							TgUsernames us2 = usernamesDao.getUsernamesByType2(us);
  							if(us2!=null){
  								week.setDj_nickname(us2.getNickname());
  							}
  							
  							money.setUsername(u.getUsername());
  							money.setStartTime(startTime);
  							money.setEndTime(endTime);
  							money.setMoneyType1(1);
  							List<TgMoney> mlist = moneyDao.getMoneysStaticByType(money);
  							if(mlist!=null && mlist.size()>0){
  								for(TgMoney m:mlist){
  									moneys +=m.getMoneys();
  								}
  							}
  							week.setXzMoneys(moneys);//当周新增业绩
  							
  							//接待测评量
  							reception.setUsername(u.getUsername());
  							reception.setStartTime(stime);
  							reception.setEndTime(etime);
  							week.setCpCount(receptionService.getZonlReceptionCount(reception));
  							
  							//成单数
  							money1.setUsername(u.getUsername());
  							money1.setEndTime(endTime);
  							Integer count =moneyService.getZonCdByMoneys(money, money1, sdf.parse(startTime), sdf.parse(endTime));
  							week.setJtCount(count);
  							
  							//市场新增业绩
  							money2.setMoneyType2(3);
  							money2.setUsername(u.getUsername());
  							money2.setStartTime(startTime);
  							money2.setEndTime(endTime);
  							List<TgMoney> clist2 = moneyDao.getMoneysStaticByType(money2);
  							
  							Double moneys2 = 0.0;
  							money3.setNickname1(u.getNickname());
  							money3.setStartTime(startTime);
  							money3.setEndTime(sdf.format(DateUtil.getTommorrowDay1(sdf.parse(endTime))));
  							mlist = moneyDao.getMoneysScStaticByType(money3);
  							if(mlist!=null && mlist.size()>0){
  								for(TgMoney m:mlist){
  									moneys2 +=m.getMoneys();
  									
  									//当周市场成单数
  									if(m.getMoneyType2()==1){
  										cdCount++;
  									}else if(m.getMoneyType2()==2){
  										money4.setStu_id(m.getStu_id());
  										clist2 = moneyDao.getMoneysStaticByType(money4);
  										if(clist2!=null && clist2.size()>0){
  											cdCount++;
  										}
  									}
  								}
  							}
  							week.setScMoney(moneys2);
  							week.setSccdCount(cdCount);
  							
  							//市场接待测评量
  							reception.setSource("3p5idbdw49di,ct5yq4jhc6c7,gx50j0s9hrr1,wtukdq8gp65h,B76B4D3BFB7A,5077779E7889");
  							week.setScCount(receptionDao.getReceCountByType(reception));
  							list.add(week);
  						}
  					}
  					
  					String name = WriterExcel.writeExcelweekXz(list, startTime, endTime);
  					result.setDefaultModel("name", name);
  				} catch (Exception e) {
  					// TODO Auto-generated catch block
  					e.printStackTrace();
  				}
  				return result;
  			}
  		});

  		return new ModelAndView("", modelMap);
  	}

  //咨询师预约到访下载
    @RequestMapping(value = "/yuyue_daofangXZ")
	public ModelAndView yuyue_daofangXZ(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, final HttpServletResponse response)
			throws Exception {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String time = request.getParameter("time");
					String nickname = request.getParameter("nickname");
					String regions = request.getParameter("regions");
					
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
					
					TgOffice office = new TgOffice();
					List<TgOffice> olist = tgOfficeDao.getOfficeName(office);
					String offices = "";
					if(olist!=null && olist.size()>0){
						for(TgOffice o:olist){
							offices +=o.getName()+",";
						}
					}
					
					TgUserinfo user  = new TgUserinfo();
					String startTime = "";
					String endTime = "";
					if((time!=null && !time.equals(""))){
	   					startTime = sdf.format(DateUtil.getMonthFirst(time));
	   					endTime = sdf.format(DateUtil.getMonthLast(time));
	   				}else{
	   					time = sd.format(new Date());
	   					startTime = sdf.format(DateUtil.getMonthFirst(sdf.format(new Date())));
	   					endTime = sdf.format(DateUtil.getMonthLast(sdf.format(new Date())));
	   				}
					user.setJob("在线课程顾问");
					user.setRegions(regions);
	   				user.setNickname(nickname);
	   				List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user);
	   				user.setJob("课程顾问");
	   				List<TgUserinfo> uList =userinfoDao.getUserInfoByUserInfo(user);
	   				uList.addAll(uList1);
	   				if(uList!=null && uList.size()>0){
	   					TgReserve reserve = new TgReserve();
	   					for(TgUserinfo u:uList){
	   						reserve.setUsername(u.getUsername());
	   						reserve.setNon(0);
	   						reserve.setState(2);
	   						reserve.setSdate(sdf.parse(startTime));
	   						reserve.setEdate(sdf.parse(endTime));
	   						List<TgReserve> rlist = reserveDao.getReserve(reserve);
	   						if(rlist!=null && rlist.size()>0){
	   							HashMap<String, Integer> hs = new HashMap<String, Integer>();
	   							Integer zon = 0;
	   							for (TgReserve r : rlist) {
	   								Integer count = 1;
	   								if(r.getReceuser()!=null && !r.getReceuser().equals("")){
	   									if(!r.getReceuser().equals(u.getNickname())){
		   									if(r.getProvince()!=null && !"".equals(r.getProvince())){
		   										if (hs.get(r.getReceuser()) != null) {
				   									count = hs.get(r.getReceuser()) + 1;
				   								}
				   								hs.put(r.getReceuser(), count);
				   								zon++;
		   									}
		   								}
	   								}else{
	   									if(!r.getReceptioner().equals(u.getNickname())){
		   									if(r.getProvince()!=null && !"".equals(r.getProvince())){
		   										if (hs.get(r.getReceptioner()) != null) {
				   									count = hs.get(r.getReceptioner()) + 1;
				   								}
				   								hs.put(r.getReceptioner(), count);
				   								zon++;
		   									}
		   								}
	   								}
	   								
	   							}
	   							u.setTotrate(hs+"");
	   							u.setZonCount(zon);
	   							
	   							
	   						}
	   						
	   					}
	   				}
					String name = WriterExcel.writeExcelyydfXz(uList, endTime);
  					result.setDefaultModel("name", name);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}
    
    
  
}
